package com.dyc.maitaole.controller;

import com.dyc.maitaole.entity.User;
import com.dyc.maitaole.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public ModelAndView login(String userName,String userPassword){
        User user = userService.login(userName, userPassword);
        ModelAndView modelAndView = new ModelAndView("/index.jsp");
        modelAndView.addObject("user",user);
        return modelAndView;
    }

    @RequestMapping("/register")
    public ModelAndView register(String userName,String userPassword){
        User user = userService.login(userName, userPassword);
        ModelAndView modelAndView = new ModelAndView("/login.jsp");
        modelAndView.addObject("user",user);
        return modelAndView;
    }

}
